//package com.shen.shenproject.retrofit
//
//import com.shen.shenproject.coroutine.retrofit.Repo
//import okhttp3.internal.platform.Platform
//import retrofit2.Call
//import retrofit2.Callback
//import retrofit2.Response
//import retrofit2.Utils
//import java.io.IOException
//import java.lang.reflect.InvocationHandler
//import java.lang.reflect.Method
//
///**
// * author:  shen
// * date:    2020/9/29
// *
// * Retrofit.create()  实际上 返回的对象  相当于下面这个
// *
// */
//class RealService : ShenRetrofitApi{
//
//    val invocationHandler = object : InvocationHandler {
//        private val platform = Platform.get()
//        private val emptyArgs = arrayOfNulls<Any>(0)
//
//        @Throws(Throwable::class)
//        override fun invoke(proxy: Any, method: Method, args: Array<Any>?): Any? {
//            // If the method is a method from Object then defer to normal invocation.
//            if (method.declaringClass == Any::class.java) {
//                return method.invoke(this, *args)
//            }
//            return if (platform.isDefaultMethod(method)) {
//                platform.invokeDefaultMethod(method, service, proxy, *args)
//            } else loadServiceMethod(method).invoke(args ?: emptyArgs)
//        }
//    }
//
//    override fun listRepos(user: String): Call<List<Repo>> {
//        val method = ShenRetrofitApi::class.java.getMethod("listRepos")
//        return invocationHandler.invoke(this, method, null)
//    }
//
//    override fun getUser(user: String): Call<List<Repo>> {
//        val method = ShenRetrofitApi::class.java.getMethod("getUser")
//        return invocationHandler.invoke(this, method, null)
//    }
//
//    fun enqueue(callback: Callback<T?>) {
//        Utils.checkNotNull(callback, "callback == null")
//        delegate.enqueue(object : Callback<T?> {
//            override fun onResponse(call: Call<T?>, response: Response<T?>) {
//                callbackExecutor.execute(Runnable {
//                    if (delegate.isCanceled()) {
//                        // Emulate OkHttp's behavior of throwing/delivering an IOException on cancellation.
//                        callback.onFailure(this@ExecutorCallbackCall, IOException("Canceled"))
//                    } else {
//                        callback.onResponse(this@ExecutorCallbackCall, response)
//                    }
//                })
//            }
//
//            override fun onFailure(call: Call<T?>, t: Throwable) {
//                callbackExecutor.execute(Runnable {
//                    callback.onFailure(this@ExecutorCallbackCall, t)
//                })
//            }
//        })
//    }
//}